/**
 * 测试用例
 */
var testUnit1 = {
    editor: null,
    //段落测试
    paragraphSection: [
        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontFamily: "楷体", fontSize: 14 } },
        { command: "insertText", param: "• 设置段落样式：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontWeight: "normal", fontSize: 12 } },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "1.居左对齐" },

        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "center" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "2.居中对齐" },

        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "right" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "3.居右对齐" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "4.两端对齐：" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "justify-except-last" } },
        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal" } },
        { command: "insertText", param: "患者自诉随年龄增长, 面部皮肤逐渐老化, 额部欠饱满, 面部轮廓线条欠柔和, " },
        { command: "insertText", param: "颜面部欠对称皮肤出现褶皱, 做表情时加深加重, 近2年来自觉严重影响美观。 " },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "5.分散对齐：" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "justify" } },
        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal" } },
        { command: "insertText", param: "患者自诉随年龄增长, 面部皮肤逐渐老化, 额部欠饱满, 面部轮廓线条欠柔和, " },
        { command: "insertText", param: "颜面部欠对称皮肤出现褶皱, 做表情时加深加重。 " },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "6.首行缩进：" },

        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textIndent: 100 } },
        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal" } },
        { command: "insertText", param: "患者自诉随年龄增长, 面部皮肤逐渐老化, 额部欠饱满, 面部轮廓线条欠柔和, " },
        { command: "insertText", param: "颜面部欠对称皮肤出现褶皱, 做表情时加深加重。 " },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left", textIndent: 0 } },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "7.设置行间距(2倍)：" },

        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { lineHeight: 2 } },
        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal" } },
        { command: "insertText", param: "患者自诉随年龄增长, 面部皮肤逐渐老化, 额部欠饱满, 面部轮廓线条欠柔和, " },
        { command: "insertText", param: "颜面部欠对称皮肤出现褶皱, 做表情时加深加重。 " },

        { command: "insertEnter" },
        { command: "insertEnter" },
    ],
    //文本样式测试
    textStyleSection: [
        { command: "setParagraphStyle", param: { textIndent: null, textAlign: "left", lineHeight: 1.5 } },
        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontSize: 14 } },
        { command: "insertText", param: "• 设置文本样式：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal", color: "#606266", fontSize: 14, color: "#F56C6C" } },
        { command: "insertText", param: "字体：宋体，加粗，大小14，颜色#F56C6C" },

        { command: "insertEnter" },

        {
            command: "setStyle", param: {
                fontFamily: "微软雅黑", fontSize: 11, fontStyle: "italic", textDecoration: "underline",
                fontWeight: "normal", fontSize: 12, color: "#409EFF"
            }
        },
        { command: "insertText", param: "字体: 微软雅黑，斜体，下划线，大小11，颜色#409EFF" },

        { command: "insertEnter" },

        {
            command: "setStyle", param: {
                fontFamily: "宋体", fontSize: 11, fontStyle: "normal", fontWeight: "normal", textDecoration: "line-through",
                fontWeight: "normal", fontSize: 13, color: "red"
            }
        },
        { command: "insertText", param: "字体: 宋体，删除线，大小13，颜色red" },

        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "楷体", textDecoration: null, fontSize: 11, fontWeight: "normal", color: "#fff", backgroundColor: "#67C23A" } },
        { command: "insertText", param: "字体: 楷体，大小11，颜色#fff, 背景色#67C23A" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        {
            command: "setStyle", param: {
                fontFamily: "楷体", fontWeight: "normal", color: "#606266", fontSize: 14, fontWeight: "normal",
                textDecoration: null, fontSize: 14, color: "#000", backgroundColor: ""
            }
        },
        { command: "insertText", param: "• 设置文本间距(间距2px)：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { letterSpacing: "2", fontWeight: "normal", fontSize: 12 } },
        { command: "insertText", param: "为求改善, 今日至我科就诊。患者近来饮食可, 精神可, 睡眠可, 大小便未见异常, 体重无明显变化。" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setParagraphStyle", param: { textAlign: "left" } },
        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontSize: 14 } },
        { command: "insertText", param: "• 设置上标下标：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "Arial", fontWeight: "normal", fontSize: 14 } },

        { command: "insertText", param: "x" },
        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sup: true } },
        { command: "insertText", param: "2" },

        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sup: false } },
        { command: "insertText", param: " + " },

        { command: "insertText", param: "y" },
        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sup: true } },
        { command: "insertText", param: "2" },

        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sup: false } },
        { command: "insertText", param: " = " },

        { command: "insertText", param: "log" },
        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sub: true } },
        { command: "insertText", param: "2" },
        { command: "setStyle", param: { fontWeight: "normal", fontSize: 14, sup: false } },
        { command: "insertText", param: "N" },

        { command: "insertEnter" },
        { command: "insertEnter" },
    ],
    //
    //插入元素测试
    insertElementSection: [
        { command: "setParagraphStyle", param: { textIndent: null, textAlign: "left", lineHeight: 1.5 } },
        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontSize: 14 } },
        { command: "insertText", param: "• 插入内容：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "1.插入一段HTML" },
        { command: "insertEnter" },
        {
            command: "insertHTML",
            option: { type: "html" },
            param: ["<div>从场景上说，MessageBox 的作用是美化系统自带的" +
                "<span style='color:red;font-weight:bold;'>alert</span>、" +
                "<span style='color:blue;font-weight:bold;'>confirm</span> 和 " +
                "<span style='color:green;font-weight:bold;'>prompt</span>，" +
                "因此适合展示较为简单的内容。如果需要弹出较为复杂的内容，请使用 Dialog。</div>"],
        },
        { command: "insertEnter" },
        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "2.插入图片" },
        { command: "insertEnter" },
        { command: "insertImage", param: [tu1_image_1] },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "3.插入复选框" },
        { command: "insertEnter" },
        { command: "insertCheckBox", option: { title: "B超", width: 120 } },
        { command: "insertCheckBox", option: { title: "CT", width: 120 } },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "4.插入单选框" },
        { command: "insertEnter" },
        { command: "insertRadio", option: { title: "自费账户", name: "account", width: 120 } },
        { command: "insertRadio", option: { title: "医保账户", name: "account", width: 120 } },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "5.插入输入域" },
        { command: "insertEnter" },
        { command: "setStyle", param: { fontFamily: "宋体", fontSize: 11, fontWeight: "normal" } },
        { command: "insertText", param: "(a) 输入效果" },
        { command: "insertEnter" },
        { command: "insertInputArea" },
        { command: "insertEnter" },
        { command: "insertText", param: "(b) 下拉框-列表" },
        { command: "insertEnter" },
        { command: "insertInputArea", option: { type: "dropdown", dropdowntype: "list" } },
        { command: "insertEnter" },
        { command: "insertText", param: "(c) 下拉框-日期" },
        { command: "insertEnter" },
        { command: "insertInputArea", option: { type: "dropdown", dropdowntype: "calendar", viewMode: "date" } },
        { command: "insertEnter" },
        { command: "insertText", param: "(d) 下拉框-时间" },
        { command: "insertEnter" },
        { command: "insertInputArea", option: { type: "dropdown", dropdowntype: "calendar", viewMode: "time" } },
        { command: "insertEnter" },
        { command: "insertText", param: "(e) 下拉框-日期时间" },
        { command: "insertEnter" },
        { command: "insertInputArea", option: { type: "dropdown", dropdowntype: "calendar", viewMode: "datetime" } },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "6.插入表格" },
        { command: "insertEnter" },
        { command: "insertTable", option: { rowCount: 3, columnCount: 3 } },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setRange", option: { moveToEnd: true } },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "7.插入页码" },
        { command: "insertEnter" },
        { command: "insertPageNum" },
        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "8.插入直线" },
        { command: "insertEnter" },
        { command: "insertLine" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "微软雅黑", fontSize: 11, fontWeight: "normal", color: "#606266" } },
        { command: "insertText", param: "9.插入分页符" },
        { command: "insertEnter" },
        { command: "insertPageBreak" },
        { command: "insertEnter" },
        { command: "insertEnter" },
    ],
    //光标移动测试
    caretMoveSection: [
        { command: "setParagraphStyle", param: { textIndent: null, textAlign: "left", lineHeight: 1.5 } },
        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontSize: 14 } },
        { command: "insertText", param: "• 测试光标移动：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal", fontSize: 12, backgroundColor: "#eee" } },
        { command: "insertText", param: "光标将在此段文字来回移动两次，最后回车进入下一个测试环节，耗时若干秒，请耐心等待", option: { id: 1111 } },
        { command: "setRange", param: test_unit_createRange("#1111", true, 39, -1), delay: 80 },
        { command: "setRange", param: test_unit_createRange("#1111", true, -1, 39), delay: 80 },
        { command: "setRange", param: test_unit_createRange("#1111", true, 39, -1), delay: 20 },
        { command: "setRange", param: test_unit_createRange("#1111", true, -1, 39), delay: 20 },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "楷体", fontWeight: "normal", fontSize: 14 } },
        { command: "insertText", param: "• 测试选择内容：" },

        { command: "insertEnter" },
        { command: "insertEnter" },

        { command: "setStyle", param: { fontFamily: "宋体", fontWeight: "normal", fontSize: 12, backgroundColor: "#eee" } },
        { command: "insertText", param: "在该段文字范围内不停变化选择五次不同内容，然后停留在最后一次选择内容后，回车进入下一个测试环节", option: { id: 2222 } },
        { command: "setRange", param: {id: "#2222", start: 2, end: 8}, delay: 80 },

        { command: "insertEnter" },
        { command: "insertEnter" },
    ],
    //删除内容测试
    deleteSection: [

    ],
    execute: function () {
        if (this.editor == null) return;

        //设定文档锁定，禁止键盘和鼠标输入
        this.editor.document.setSetting({
            docMode: ssDict.sDocMode.LOCKED
        });

        var data = [
            // ...this.textStyleSection,
            // ...this.paragraphSection,
            // ...this.insertElementSection,
            ...this.caretMoveSection
        ];

        var i = 0;
        var j = 0;

        var item = data[i++];

        var insertElement = () => {
            setTimeout(() => {
                var canIteration = typeof (item.param) == "string" || Array.isArray(item.param);

                this.editor.executeCommand(item.command,
                    canIteration ? item.param[j++] : item.param, item.option);

                if (!item.param || !item.param.length || (canIteration && j >= item.param.length)) {
                    item = data[i++];
                    j = 0;
                }

                if (!item) {
                    //恢复到设计模式
                    this.editor.document.setSetting({
                        docMode: ssDict.sDocMode.DESIGN
                    });
                    return;
                }

                insertElement();
            }, item.delay ? item.delay : 0);
        }

        insertElement();

    }
};
